<%--
  Created by IntelliJ IDEA.
  User: hkw14
  Date: 2021/5/2
  Time: 23:46
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>销售订单列表</title>
    <link rel="stylesheet" href="${ctx}/resource/layui/css/layui.css">
</head>
<body>
<div class="layui-container">
    <div>
        <div class="layui-form layui-form-pane">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">
                        商品名
                    </label>
                    <div class="layui-input-inline">
                        <input class="layui-input" placeholder="商品名" id="goodName"/>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">
                        用户名
                    </label>
                    <div class="layui-input-inline">
                        <input class="layui-input" placeholder="用户名" id="userName"/>
                    </div>
                </div>
                <div class="layui-inline">
                    <div class="layui-inline">
                        <button class="layui-btn" id="searchBtn">查询</button>
                    </div>
                </div>
            </div>

        </div>
    </div>
    <%--    显示区域--%>
    <div>
        <table id="dataTable" lay-filter="dataTableFilter"></table>
    </div>
</div>
<script type="text/html" id="headBtns">
    <button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="del">删除商品</button>
</script>
<!-- 行工具栏 -->
<script type="text/html" id="rowBtns">
    <button class="layui-btn layui-btn-sm layui-btn-warm layui-btn-fluid" lay-event="modify">修改商品信息</button>
</script>
<script src="${ctx}/resource/layui/layui.js"></script>
<script type="text/javascript">
    //用户列表的JS
    layui.use(['form','jquery','table','layer'],function () {
        //初始化对象
        var form = layui.form;
        var  $ = layui.jquery;
        var  table = layui.table;
        var  layer = layui.layer;
        //初始化表格
        var t = table.render({
            id:"dataTableId",
            elem:'#dataTable',//表格容器
            url:"sealOrder.do?service=list",//数据接口
            page:true,//开启分页
            height:550,
            toolbar:"#headBtns",
            //表头信息
            cols:[[
                {type:"checkbox",width:"80"},
                {field:"iD",title:"订单ID",width:"80"},
                {field:"goodName",title:"商品名",width:"100"},
                {field:"userName",title:"用户名",width:"100"},
                {field: 'creationTime', width:160,title: '创建时间',templet:"<div>{{layui.util.toDateString(d.creationTime)}}</div>"},
                {field:"number",title:"数量",width:"100"},
                {field:"sum",title:"总计金额",width:"100"},
            ]],
            parseData:function (res) {//数据格式解析
                return{
                    "code":res.code,
                    "msg":res.msg,
                    "count":res.data.count,
                    "data":res.data.list
                };
            },
            response:{//设置相应码
                statusCode: 200 //规定成功的状态码，默认：0
            }
        });

        //搜索按钮事件
        $("#searchBtn").click(function(){
            var goodName = $("#goodName").val();
            var providerName = $("#providerName").val();
            var goodsType = $("#goodsType").val();
            var brand = $("#brand").val();

            t.reload({
                where:{
                    'goodName':goodName,
                    'providerName':providerName,
                    'goodsType':goodsType,
                    'brand':brand
                }
            });
        });

        table.on("toolbar(dataTableFilter)",function(d){
        var event = d.event;
        if(event == 'del'){//批量删除
            //获取选中的数据
            var checkStatus = table.checkStatus('dataTableId');
            var data = checkStatus.data;
            if(data.length == 0){
                layer.msg("请选择要删除的数据");
                return false;
            }
            //拼接要传输给后台的id参数
            var ids = "";
            for(var i=0;i<data.length;i++){
                ids = ids+"ID="+data[i].iD+"&"
                // alert(ids);
            }
            layer.confirm("你确定要删除吗?",function(index){
                $.post("sealOrder.do？type=delete&"+ids,function(rs){
                    if(rs.code != 200){
                        layer.msg(rs.msg);
                    }else{
                        layer.msg("删除成功");
                        //关闭弹层
                        layer.close(index);
                        //重新加载数据
                        $("#searchBtn").click();
                    }
                });

            });
        }
    });
});
</script>
</body>
</html>
